package com.imjohn.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.imjohn.entity.Aticle;
import com.imjohn.mapper.PageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PageService {
    @Autowired
    PageMapper pageMapper;
    /**
     * 分页查询 -- 业务层接口的实现类
     * @param pageNum 当前页
     * @param pageSize 每页显示的条数
     * @return
     */
    public PageInfo<Aticle> GetAllAticle ( int pageNum, int pageSize ) {
        PageInfo<Aticle> pageInfo = null;
        //告诉分页组件，你需要显示的页码和每页显示的条数
        PageHelper.startPage(pageNum,pageSize);
        //查询所有的用户信息
        List<Aticle> list = pageMapper.GetAllAticle( pageNum, pageSize);
        pageInfo = new PageInfo<>(list,pageSize);
        return pageInfo;
    }
    public PageInfo<Aticle> GetByNameAticle ( int pageNum, int pageSize, String userName ) {
        PageInfo<Aticle> pageInfo = null;
        //告诉分页组件，你需要显示的页码和每页显示的条数
        PageHelper.startPage(pageNum,pageSize);
        //查询所有的用户信息
        List<Aticle> list = pageMapper.GetByNameAticle( pageNum, pageSize, userName);
        pageInfo = new PageInfo<>(list,pageSize);
        return pageInfo;
    }

}
